-
Notifications
You must be signed in to change notification settings - Fork 44
Conversation
const fileName = name + '.tar.gz'; | ||
let file = fs.createWriteStream(fileName); | ||
|
||
await new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we return the Promise here? It will be awaited by the caller
}) | ||
}) | ||
.catch(error => { | ||
throw new Error('Extracting tar file failed'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should reject the error
here?
const { exec } = require('child_process'); | ||
import request from 'request'; | ||
|
||
export async function importProjectFromTar(tarFile: string, name: string, dest: string): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we get rid of the await
below this doesn't need to be a async function
@laven26 How are the changes coming along? |
fs.removeSync(fileName); | ||
}); | ||
|
||
resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed something... this actually needs to go into exec callback above. And removeSync should have try/catch
if (err)
return reject(err);
try {
fs.removeSync(fileName);
}
catch (err) {
// probably just log this here.
}
resolve();
resolve(); | ||
|
||
}) | ||
.on('error', (error) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more concise syntax here can be `.on('error', reject);
@@ -47,6 +48,16 @@ export default class ProjectInitializer { | |||
return this.initializeExistingProject(); | |||
} | |||
|
|||
async initializeProjectFromTar( | |||
tarFile: string | |||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed return type here
LGTM |
@rajivnathan can you help review this? Thank you |
@hhellyer , can you help review this? Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a rebase to bring it up to date as well as we've actually added the request module in the meantime. If you wanted to pull out the asyncHttpDownload
or the execAsync
function from #100 to a utility file that might be good but not essential.
src/initialize/src/main.ts
Outdated
@@ -42,7 +42,9 @@ export async function initializeProject(projectName: string, projectDirectory: s | |||
const projectInitializer = new ProjectInitializer(projectName, projectDirectory); | |||
|
|||
try { | |||
if (isGitCloneRequired(projectName, gitRepository)) { | |||
if (gitRepository.endsWith("tar.gz")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not that comfortable with overloading GIT_REPO to also mean "any url to a tar.gz". Can we just use a different env var and check if that was set or if GIT_REPO was set?
resolve(); | ||
}); | ||
}) | ||
.on('error', reject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this remove the empty or partial file if the download fails? (e.g. on a bad url or github being down)
export function importProjectFromTar(tarFile: string, name: string, dest: string): Promise<void> { | ||
|
||
const fileName = name + '.tar.gz'; | ||
const file = fs.createWriteStream(fileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be an absolute filename, otherwise it will just be created in the current working directory (and I'm not sure exactly where that will be in all cases).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use /tmp
not /app
. /app
exists in the initialiser pod but the initialiser code is run directly as an npm when we are in che and /app
doesn't exist there.
(Also /tmp
is a better location for temporary files.)
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
`PROJ_NAME=${projectName}`, | ||
`GIT_REPO=${gitInfo.repo}`, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gitInfo.branch
check below can go into this else
block right? Since it would be applicable only for non-tarball scenario
`PROJ_NAME=${projectName}`, | ||
`GIT_REPO=${gitInfo.repo}`, | ||
); | ||
if (gitInfo.repo.endsWith("tar.gz")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor nit: while you're making changes, could you make this check for .tar.gz
? (add dot in the front)
Signed-off-by: laven-s <laven.s@ibm.com>
resolve(); | ||
}); | ||
}) | ||
.on('error', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's an err
passed here you can then pass it to reject
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
Thanks for the reviews Andrew and Howard |
Signed-off-by: laven-s laven.s@ibm.com